Skip to content

fix inconsistent syntax highlighting for field of type inspect._ParameterKind #4751 - #4794

Closed
asukaminato0721 wants to merge 5 commits into
pyrefly-org:mainfrom
asukaminato0721:4751
Closed

asukaminato0721 wants to merge 5 commits into
pyrefly-org:mainfrom
asukaminato0721:4751

Conversation

@asukaminato0721

Copy link
Copy Markdown
Collaborator

Summary

Fixes #4751

fixes incorrect semantic highlighting for narrowed enum instance attributes.

Previously, holder.kind could be classified as an enumMember after narrowing.

Now instance attributes such as holder.kind remain property, actual enum members accessed through the enum class, such as E.A, remain enumMember.

Test Plan

add test

@meta-cla meta-cla Bot added the cla signed label Sep 3, 2026
@github-actions github-actions Bot added the size/m label Sep 3, 2026
@meta-codesync

meta-codesync Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D118576862. (Because this pull request was imported automatically, there will not be any future comments.)

@github-actions

This comment has been minimized.

@kinto0 kinto0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love this special-case. until now, all attributes could be colored based on only their type. is this the only exception? Is it true that accessed_on_class + being an enum are the only qualifiers?

Comment thread pyrefly/lib/state/semantic_tokens.rs Resolved
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Comment thread pyrefly/lib/lsp/wasm/semantic_tokens.rs Resolved
use crate::common::lsp_args;
use crate::common::pytorch_root_or_skip;

const MODULE: &str = "torch/nn/modules/module.py";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the result of this benchmark? does this file have enough enum-literal attribute accesses?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it's neutral, do we need to commit this benchmark? or should we just run it?

Comment thread pyrefly/lib/lsp/wasm/semantic_tokens.rs Outdated
&ast,
&|range| self.get_type_trace(handle, range),
&|range, base_range, name| {
let ty = self.get_type_trace(handle, range)?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move this into a named function? I think it's too big for a closure

Comment thread pyrefly/lib/lsp/wasm/semantic_tokens.rs Outdated
let kind = attribute_symbol_kind_from_type(&ty)
.to_lsp_semantic_token_type_with_modifiers()
.0;
let members = match &ty {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reusable API that does this?

Comment thread pyrefly/lib/test/lsp/semantic_tokens.rs Resolved
Comment thread pyrefly/lib/state/semantic_tokens.rs Resolved
Comment thread pyrefly/lib/test/lsp/semantic_tokens.rs Resolved
Comment thread pyrefly/benches/README.md Outdated
Comment on lines +65 to +68
`NoTelemetry` excludes the telemetry backend's per-solve work. Internal timing
and telemetry event construction still execute.
For a base/head comparison, copy this benchmark and its registration to the
base revision, then use the same pinned source, compiler, and arguments.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we keep the benchmark, can we drop the NoTelemetry and base/head copy notes? They describe how this PR was measured rather than how to use the benchmark.

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@kinto0 kinto0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

@kinto0

kinto0 commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Thanks for the fix! It looks good. We are merging it now, and we are handling a few small items in follow-up diffs that land with it:

@meta-codesync meta-codesync Bot closed this in 172de12 Nov 13, 2026
@meta-codesync meta-codesync Bot added the Merged label Nov 13, 2026
@meta-codesync

meta-codesync Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

This pull request has been merged in 172de12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

inconsistent syntax highlighting for field of type inspect._ParameterKind

4 participants